package StudyCode.summary.Basic.mystring;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class StringWhitespaceRemove {

	public static void main(String[] args) {
		String str = "           Hello        World       !";
		System.out.println("删除前:" + str);
		System.out.println("删除后:" + removeDuplicateWhitespace(str));
	}

	public static CharSequence removeDuplicateWhitespace(CharSequence inputStr) {
		String patternStr = "\\s+";
		String replaceStr = " ";
		Pattern pattern = Pattern.compile(patternStr);
		Matcher matcher = pattern.matcher(inputStr);
		return matcher.replaceAll(replaceStr);
	}
}
